<template>
  <div>
    <el-dialog title="转号" :visible.sync="dialogVisible" append-to-body width="50%" class="dialog"
      element-loading-background="rgba(0, 0, 0, 0.8)" :before-close="handleClose" :close-on-click-modal="false" center>
      <el-tree :data="doctorList" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
      <div slot="footer">
        <el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
        <el-button @click="handleClose('ruleForm')">取消</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { ApiGetDepartmentDoctorList, ApiPostOrderChangeDoctor } from '../../../api/index'
import { mapState } from "vuex";
export default {
  name: 'prescribing',
  computed: {
    ...mapState(["userState"]),
  },
  props: ['id'],
  data() {
    return {
      selectArr: [],
      dialogVisible: false,
      ruleForm: {
        ICD: "",
        ICD1: "",
        type: "",
        main: "",
        prescribeMedicine: ""
      },
      defaultProps: {
        children: 'doctors',
        label: 'name'
      },
      doctorList: [],
      nodeObj: {}
    }
  },
  methods: {
    //选中的列表
    handleNodeClick(e) {
      this.nodeObj = e
    },


    show() {
      this.dialogVisible = true
      this.getDoctorList()
    },
    getDoctorList() {
      ApiGetDepartmentDoctorList({ except: this.userState.id }).then(res => {
        this.doctorList = res.data
      })
    },



    //导入患者描述信息
    /*  importPatientInfo() {
 
     } */

    handleClose() {
      this.dialogVisible = false
    },

    submitForm() {
      this.$confirm(`是否确认转诊${this.nodeObj.name}医生?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          console.log(this.nodeObj)
          ApiPostOrderChangeDoctor({ order_id: this.id, department_id: this.nodeObj.sub_department_id, doctor_id: this.nodeObj.id }).then(res => {
            this.$message({
              type: "success",
              message: "转诊成功!",
            });
            this.$emit('dialogClose')
            this.handleClose()
          })
        })
        .catch((err) => {
          console.log(err)
        });
      //预览界面nodeObj

    },
    //开药

  }
}
</script>

<style>
</style>